package com.j1903.util;


import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;

public class SendSms {
    public static Client createClient(String accessKeyId,String accessKeySecret)throws Exception
    {
        Config config=new Config()
                .setAccessKeyId(accessKeyId)
                .setAccessKeySecret(accessKeySecret);
        config.endpoint="dysmsapi.aliyuncs.com";
        return new Client(config);
    }
    public static String send()
    {
        String msg=null;
        try {
            Client client=createClient
                    ("IowXhjDpIX1JbAAF", "37TW6UNMNr3gWvICStS1vOXMtTpTOr");
            SendSmsRequest request=new SendSmsRequest();
            //接收手机号
            request.setPhoneNumbers("15870861398");

            //签名
            request.setSignName("鹊仔儿");
            //设置短信模板
            request.setTemplateCode("SMS_165414699");
            //给模板变量传值，格式是json字符串
            request.setTemplateParam("{\"code\":78349859384}");
            //发送短信
            SendSmsResponse res=client.sendSms(request);
            msg=res.getBody().message;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return msg;
    }
}
